<template>
  <div>
    <!-- <div>user:{{ user }}</div> -->
    <!-- <div>手机号：<input type="text" v-model="user.phone" /></div>
    <div>昵称：<input type="text" v-model="user.nickname" /></div>
    <div>密码：<input type="text" v-model="user.password" /></div>
    <v-button @click="register">注册</v-button> -->

    <van-form @submit="register">
      <van-field
        v-model="user.phone"
        name="手机号"
        label="手机号"
        placeholder="手机号"
        :rules="[{ required: true, message: '请填写手机号' }]"
      />
       <van-field
        v-model="user.nickname"
        name="昵称"
        label="昵称"
        placeholder="昵称"
        :rules="[{ required: true, message: '请填写昵称' }]"
      />
      <van-field
        v-model="user.password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="warning" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import { reqRegister } from "../../http/http";
export default {
  data() {
    return {
      //1.初始化表单数据
      user: {
        phone: "",
        nickname: "",
        password: "",
      },
    };
  },
  methods: {
    async register() {
      let { data: res } = await reqRegister(this.user);
      if (res.code == 200) {
        alert(res.msg);
        this.$router.push("/login");
      } else {
        alert(res.msg);
      }
    },
  },
};
</script>

<style>
</style>